home *** CD-ROM | disk | FTP | other *** search
/ By Popular Request 2.0 / By Popular Request 2.0 (Arsenal Computer).ISO / amiga_6 / tiffdtyp.lha / sources / read.c < prev    next >
C/C++ Source or Header  |  1995-06-25  |  3KB  |  106 lines

  1. #include "classbase.h"
  2. #include "TIFF.h"
  3. #include "TIFFTags.h"
  4.  
  5. #define    DB(x)    ;
  6.  
  7. #define    SWAPW(a)    (Rev ? (WORD)(((UWORD)a>>8)+((((UWORD)a&0xff)<<8))) : a)
  8. #define    SWAPU(a)    (Rev ? (UWORD)(((UWORD)a>>8)+((((UWORD)a&0xff)<<8))) : a)
  9. #define    SWAPL(a)    (Rev ? (LONG)(((ULONG)a>>24)+(((ULONG)a&0xff0000)>>8)+(((ULONG)a&0xff00)<<8)+(((ULONG)a&0xff)<<24)): a)
  10.  
  11. #define TAGVAL(a,b)    (SWAPW(a->Type)==TT_BYTE ? a->CValue[b] :            \
  12.                     (SWAPW(a->Type)==TT_SHORT ? SWAPW(a->SValue[b]) :    \
  13.                     (SWAPW(a->Type)==TT_LONG ? SWAPL(a->LValue) :    \
  14.                     ~0)))
  15.  
  16. extern char Rev;
  17. BOOL ReadError=FALSE;
  18.  
  19. ULONG ASM ReadData(REG (a0) BPTR fh, register __d0 USHORT type,REG (a6) struct ClassBase *cb)
  20.  
  21. {
  22.  UBYTE Byte;
  23.  USHORT Short;
  24.  ULONG Long;
  25.  
  26.     switch(type)
  27.     {
  28.         case TT_BYTE:
  29.             if( Read(fh, &Byte,1) !=1)
  30.                 ReadError=TRUE;
  31.             return Byte;
  32.             break;
  33.         case TT_SHORT:
  34.             if( Read(fh, &Short,2) !=2)
  35.                 ReadError=TRUE;
  36.             return SWAPW(Short);
  37.             break;
  38.         case TT_LONG:
  39.             if( Read(fh, &Long,4) !=4)
  40.                 ReadError=TRUE;
  41.             return SWAPL(Long);
  42.             break;
  43.         }
  44. }/*************************** ReadData ************************/
  45.                     
  46. void ASM ReadShorts(REG (a0) BPTR fh, REG (a1) USHORT *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
  47.  
  48. {
  49.  int i,oldpos;
  50.  
  51.     DB (KPrintF ("Read Shorts %ld off %ld\n",(long)tag->Count,(long)SWAPL(tag->LValue)));
  52.     oldpos=Seek(fh, SWAPL(tag->LValue), OFFSET_BEGINNING);
  53.     DB (KPrintF ("Seek %ld\n",(long)SWAPL (tag->LValue)));
  54.     for(i=0;i<tag->Count;i++)
  55.      *buffer++=ReadData(fh,tag->Type,cb);
  56.     DB (KPrintF ("Read %ld\n",(long)tag->Count));
  57.     Seek(fh, oldpos, OFFSET_BEGINNING);
  58.     DB (KPrintF ("Seek %ld\n",(long)oldpos));
  59. }/*************************** ReadShorts ************************/
  60.  
  61. void ASM ReadLongs(REG (a0) BPTR fh, REG (a1) ULONG *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
  62.  
  63. {
  64.  int i,oldpos;
  65.  
  66.     DB (KPrintF ("Read Longs %ld\n", (long)tag->Count));
  67.  
  68.     if(tag->Count==1)
  69.     {
  70.         *buffer=TAGVAL(tag,0);
  71.         return;
  72.     }
  73.  
  74.     oldpos=Seek(fh, tag->LValue, OFFSET_BEGINNING);    
  75.     for(i=0;i<tag->Count;i++)
  76.         *buffer++=ReadData(fh,SWAPW(tag->Type),cb);
  77.     Seek(fh, oldpos, OFFSET_BEGINNING);
  78. }/*************************** ReadLongs ************************/
  79.  
  80. void ASM ReadRational(REG (a0) BPTR fh, REG (a1) ULONG *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
  81.  
  82. {
  83.  int i,oldpos;
  84.  
  85.     DB (KPrintF ("Read Rationals %ld\n", (long)tag->Count));
  86.     oldpos=Seek(fh, tag->LValue, OFFSET_BEGINNING);
  87.     for(i=0;i<tag->Count;i++)
  88.      {
  89.      *buffer++=ReadData(fh,tag->Type,cb);
  90.      *buffer++=ReadData(fh,tag->Type,cb);
  91.      }
  92.     Seek(fh, oldpos, OFFSET_BEGINNING);
  93. }/*************************** ReadRational ************************/
  94.  
  95. void ASM ReadBytes(REG (a0) BPTR fh, REG (a1) UBYTE *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
  96.  
  97. {
  98.  int i,oldpos;
  99.  
  100.     DB (KPrintF ("Read Bytes %ld\n", (long)tag->Count));
  101.     oldpos=Seek(fh, tag->LValue, OFFSET_BEGINNING);
  102.     for(i=0;i<tag->Count;i++)
  103.      *buffer++=ReadData(fh,tag->Type,cb);
  104.     Seek(fh, oldpos, OFFSET_BEGINNING);
  105. }/*************************** ReadBytes ************************/
  106.